import {createRouter, createWebHistory} from 'vue-router'
import Layout from "@/layout/LayoutView.vue";
// 引入进度条样式
import 'nprogress/nprogress.css'
import NProgress from 'nprogress'

const router = createRouter({
    history: createWebHistory(import.meta.env.BASE_URL),
    routes: [
        {
            path: '/',
            name: 'home',
            component: Layout,
            children: [
                {
                    path: '',
                    name: 'home',
                    component: () => import('../views/HomePage.vue')
                }
            ]
        },
        {
            path: '/kettle',
            name: 'kettle',
            component: Layout,
            children: [
                {
                    path: 'board',
                    name: 'board',
                    component: () => import('../views/kettle/KettleBoard.vue')
                },
                {
                    path: 'database',
                    name: 'database',
                    component: () => import('../views/kettle/database/KettleDatabase.vue')
                },
                {
                    path: 'trans',
                    name: 'trans',
                    component: () => import('../views/kettle/trans/KettleTrans.vue')
                }
            ]
        }

    ]
})

const np = NProgress
np.configure({ showSpinner: false })
np.inc()

router.beforeEach( async (to, from, next) =>{
    const title = to.meta.title
    if(title){
        document.title = title
    }
    else{
        document.title = import.meta.env.VITE_APP_TITLE
    }
    console.log(import.meta.env)
    np.start()
    next()
})

router.afterEach(()=>{
    np.done()
})

export default router
